package com.xbongbong.saas.model.impl;

import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.saas.domain.dao.ReturnedPurchaseInvoiceDao;
import com.xbongbong.saas.domain.entity.ReturnedPurchaseInvoiceEntity;
import com.xbongbong.saas.model.ReturnedPurchaseInvoiceModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author zhouwq
 * @date 2020/2/24 15:46
 */
@Service("returnedPurchaseInvoiceModel")
public class ReturnedPurchaseInvoiceModelImpl implements ReturnedPurchaseInvoiceModel {

    @Resource
    private ReturnedPurchaseInvoiceDao returnedPurchaseInvoiceDao;

    /**
     * 保存
     *
     * @param refundInvoiceEntity 实体
     * @return Integer
     */
    @Override
    public Integer save(ReturnedPurchaseInvoiceEntity refundInvoiceEntity) throws XbbException {
        if (refundInvoiceEntity.getId() == null || refundInvoiceEntity.getId() == 0) {
            return insert(refundInvoiceEntity);
        } else {
            return update(refundInvoiceEntity);
        }

    }

    /**
     * 插入
     *
     * @param entity 实体
     * @return 是否成功
     * @throws XbbException 数据库操作异常
     */
    @Override
    public Integer insert(ReturnedPurchaseInvoiceEntity entity) throws XbbException {
        return returnedPurchaseInvoiceDao.insert(entity);
    }

    /**
     * 更新
     *
     * @param entity 实体
     * @return 是否成功
     * @throws XbbException 数据库操作异常
     */
    @Override
    public Integer update(ReturnedPurchaseInvoiceEntity entity) throws XbbException {
        return returnedPurchaseInvoiceDao.update(entity);
    }

    @Override
    public List findEntitys(Map<String, Object> param) {
        return returnedPurchaseInvoiceDao.findEntitys(param);
    }

    @Override
    public Integer getEntitysCount(Map<String, Object> param) {
        return returnedPurchaseInvoiceDao.getEntitysCount(param);
    }

    @Override
    public List findEntitysWithoutSub(Map<String, Object> param) {
        return null;
    }

    /**
     * 获取发票id
     *
     * @param param 参数
     * @return 删除成功
     */
    @Override
    public List<Long> getInvoiceId(Map<String, Object> param) {
        return returnedPurchaseInvoiceDao.getInvoiceId(param);
    }


    @Override
    public Integer deleteBatchByReturnedPurchaseIdIn(String corpid, List<Long> returnedPurchaseIdList) {
        return returnedPurchaseInvoiceDao.deleteBatchByReturnedPurchaseIdIn(corpid, returnedPurchaseIdList);
    }

    /**
     * 根据退货退款list回滚数据
     *
     * @param corpid       公司id
     * @param refundIdList 退货退款id
     * @return 回滚成功
     */
    @Override
    public Integer updateRollbackByRefundId(String corpid, List<Long> refundIdList) {
        return returnedPurchaseInvoiceDao.updateRollbackByReturnedPurchaseId(corpid, refundIdList);
    }

    /**
     * 根据发票id删除
     *
     * @param invoiceId 发票id
     * @param corpid    公司id
     * @return 删除成功
     */
    @Override
    public Integer deleteByInvoiceId(Long invoiceId, String corpid) {
        return returnedPurchaseInvoiceDao.deleteByInvoiceId(invoiceId, corpid);
    }
}
